package jjn.acwing.java_basic;

import commons.LinkedListHelper;
import commons.ListNode;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;

/**
 * @author Jiang Jining
 * @since 2023-09-12 22:21
 */
public class Acwing17 {
    public int[] printListReversingly(ListNode head) {
        Deque<Integer> deque = new ArrayDeque<>();
        ListNode node = head;
        while (node != null) {
            deque.offer(node.val);
            node = node.next;
        }
        int size = deque.size();
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = deque.pollLast();
        }
        return res;
    }
    
    public static void main(String[] args) {
        ListNode listNode = LinkedListHelper.buildLinkedList(List.of(2, 3, 5));
        int[] result = new Acwing17().printListReversingly(listNode);
        System.out.println(Arrays.toString(result));
    }
}
